<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!-- Player -->
<!-- 音乐播放界面按钮  atuhor:zhujz-->
<button type="button" class="btn btn-primary" data-toggle="modal"
	data-target=".bs-example-modal-lg" id="playdock"></button>
<!-- mdi-library-plus -->
<!-- 音乐播放主界面 -->
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog"
	aria-labelledby="myLargeModalLabel">
	<div class="modal-dialog modal-lg" role="document">
		<div class="modal-content">		
			<div class="modal-body" id="mcorver">			    
				<div id="like_layer">
					<button type="button" class="mid mdi-library-plus">收藏</button>
					<button type="button" class="btn btn-default" style="background-image:url('images/dislike.png')">
					</button>
				</div>
			</div>
			<div class="modal-footer">
				<audio autoplay="autoplay" style="width: 100%" controls="controls"
					controlsList="nodownload" src=""></audio>
			</div>
		</div>
	</div>
</div>

<!--wwb 4-3  -->
	<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
	<script src="layui/layui.js" charset="utf-8"></script>
	<script src="js/bootstrap-notify.min.js"></script>
	<script type="text/javascript" src="js/lightyear.js"></script>
<script type="text/javascript">

$("#like_layer .mdi-library-plus").on("click",
			   function(){
			     //得到收藏按钮
					var cbtn=$("#like_layer .mdi-library-plus");
			     //音乐的网络id
					var imid=cbtn.attr("id");
					var name=cbtn.attr("name");
					var text=cbtn.text();
					var flag=${sessionScope.user.uid!=null}
					console.log("aaa")
					
					  if(flag){
						if(text=="收藏"){
							$.ajax({
								"url": "../ms.do?ac=collect",
								"data":{
									"op":"collect",
									"url":imid,
									"mname":name,
									"uid":'${sessionScope.user.uid}'
								},
								"success":function(data){
									if(data.isOk == true){
										layui.use(['layer','form' ],
												function() {
													var layer = layui.layer;
													layer.alert("歌曲已被收藏",
																	{
																		icon : 1,
																		skin : 'layer-ext-moon',
																		time : 3000
																	})																
												});
										cbtn.text("已收藏");
									}								
								}							
							});	
						}else{
							$.ajax({
								"url": "../ms.do?ac=collect",
								"data":{
									"op":"canclecollect",
									"url":imid,
									"mname":name,
									"uid":'${sessionScope.user.uid}'
								},
								"success":function(data){
									if(data.isOk == true){
										layui.use(['layer','form' ],
												function() {
													var layer = layui.layer;
													layer.alert("歌曲已取消收藏",
																	{
																		icon : 1,
																		skin : 'layer-ext-moon',
																		time : 3000
																	});																
												});
										cbtn.text("收藏");
									}								
								}							
							});	
						}
					}else{
						
						layui.use(['layer','form' ],
								function() {
									var layer = layui.layer;
									console.log("我没登入");
									layer.alert("请先登入！！",
													{
														icon : 2,
														skin : 'layer-ext-moon',
														time : 3000
													})
												
								})
					}
					 
			 
});
/**
* 4-2 wwb 新增：点击音乐时，获取到当前音乐在数据库中的id
*/
$(document).on(
			'click',
			'.playit',
			function() {
				//获取到音乐id
				var musicID = $(this).attr("id");
				var mname = getMusicName(musicID);
				var url = getMusicUrl(musicID);
				var flag=${sessionScope.user!=null};
				//var uid=${sessionScope.user.uid};
				console.log(typeof(url));
				if (url!=null && url!="") {
					$("#like_layer .mdi-library-plus").attr("id", musicID);
					$("#like_layer .mdi-library-plus").attr("name",getMusicName(musicID));
					
					if(flag){
						$.ajax({
							"url": "../ms.do?ac=searchMid",
							"data":{
								"mname":mname,
								"musicId":musicID,
								"uid":'${sessionScope.user.uid}'
							},
							"success":function(data){
								if(data.msg=="收藏"){
									$("#like_layer .mdi-library-plus").text("收藏");
								}else{
									$("#like_layer .mdi-library-plus").text("已收藏");
								}								
							},
						})
					}
				}
			});
</script>
